#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int t;
int ksm(int x,int p)
{
	int res=1;
	while(p)
	{
		if(p&1) res=res*x;
		x=x*x;
		p>>=1;
	}
	return res;
}
signed main()
{
	freopen("alien.in","r",stdin);
	freopen("alien.out","w",stdout);
	t=read();
	while(t--)
	{
		int a=read(),b=read(),c=read();
		int ans=0;
		for(int i=1;i<=a;i++)
			for(int j=1;j<=b;j++)	
				for(int k=1;k<=c;k++)
					if(ksm(j,i)==ksm(i,k)) ++ans;
		write(ans),puts("");
	}
	return 0;
}
